from marshmallow import Schema, fields, validate


class AddArticleSchema(Schema):
    title = fields.Str(required=True,validate=validate.Length(min=1,error="文章标题不为空"))
    content = fields.Str(required=True,validate=validate.Length(min=1,error="文章内容不为空"))

    coverImg = fields.Str(required=True)
    state = fields.Str(required=True, validate=validate.OneOf(['已回顾', '待回顾'],error="必须为‘已回顾’或者'待回顾'"))
    categoryId = fields.Integer(required=True)


class UpdateArticleSchema(Schema):
    id = fields.Integer(required=True)
    title = fields.Str(required=True,validate=validate.Length(min=1,error="文章标题不为空"))
    content = fields.Str(required=True,validate=validate.Length(min=1,error="文章内容不为空"))
    coverImg = fields.Str(required=True)
    state = fields.Str(required=True, validate=validate.OneOf(['已回顾', '待回顾'],error="必须为‘已回顾’或者'待回顾'"))
    categoryId = fields.Integer(required=True)


class ListArticleSchema(Schema):
    pageNum = fields.Integer(
                         required=True,
                         validate=lambda n: n > 0,
                         error_messages={"invalid": "pageNum must be a positive integer"})
    pageSize = fields.Integer(
                          required=True,
                          validate=lambda n: n > 0,
                          error_messages={"invalid": "pageSize must be a positive integer"})
    categoryId = fields.Integer(allow_none=True, validate=lambda n: n is None or n >= 0,
                            error_messages={"invalid": "categoryId must be a non-negative integer if provided"})
    state = fields.Str(allow_none=True, validate=validate.OneOf(['已回顾', '待回顾']))


